-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support runtime Topic designation #44
Conversation
pub struct Topic(&'static str); | ||
// A survey of common topics found lengths between 16 and 35 bytes | ||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
pub struct Topic(SmallString<[u8; 36]>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did run into this problem, since I am creating topic names dynamically - but worked around it by leaking the strings and then using a hashmap to cache the mapping from (site id, prio) -> &'static str
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess there's a reasonable bound on that combination, so that's not the worst. But we can do better!
TopicSink::new( | ||
client.client.publish_topic_sink( | ||
TopicName::new(topic.as_ref()) | ||
.into_project_topic_name(client.project()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This particular line is what I think needs to change for me to send messages across various projects. Though you might be wanting to address that in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, different PR
pub struct Topic(&'static str); | ||
// A survey of common topics found lengths between 16 and 35 bytes | ||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
pub struct Topic(SmallString<[u8; 36]>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this saying we can support any string up to 36Bytes? I wonder if any of our topics exceed that? Or is this similar to a stackvec and will falback to heap allocation if we exceed that threshold?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's backed by SmallVec, which yeah does the fallback to heap
4d1bb6c
to
da94e9f
Compare
Previously the Topic type was only constructible from static strings. This works for code-gen messages, but doesn't work if the topic needs to be determined at runtime. This change permits constructing Topics from arbitrary strings
da94e9f
to
d1726e9
Compare
Previously the Topic type was only constructible from static strings. This works for code-gen messages, but doesn't work if the topic needs to be determined at runtime. This change permits constructing Topics from arbitrary strings